SRC           = kernel.c core.S aic.c interrupt.c led.c memory.c lib.c serial.c timer.c  vtable_asm.S  \
mem_struct.c kmem.c  mem_test.c list.c waitqueue.c process_asm.o process.c tasks.c mmu.c mmu_asm.S

OBJ           = kernel.o core.o aic.o interrupt.o led.o memory.o lib.o serial.o timer.o  vtable_asm.o  \
 mem_struct.o kmem.o  mem_test.o list.o waitqueue.o process_asm.o process.o tasks.o mmu.o mmu_asm.o


CC            = arm-elf-gcc
CFLAGS        = -Wall -fno-builtin -g 
LD            = arm-elf-ld
LSCRIPT       = link_sdram.ld
OBJCOPY       = arm-elf-objcopy
MKIMAGE       = mkimage
MKIMAGE_FLAGS = -A arm -O linux -T kernel -C none -a 0x22000000 -e 0x22000000
IMAGE         = kernel
BOOTIMAGE     = system.img
DEPENDFILE    = depend

all:	$(BOOTIMAGE)

.PHONY: clean dep

clean:
	rm -f *.o *~
	rm -f $(IMAGE) $(IMAGE).bin $(BOOTIMAGE)

%.o: %.c
	$(CC) $(CFLAGS) -c $<

%.o: %.S 
	$(CC) $(CFLAGS) -c -x assembler $<

dep: $(SRC)
	$(CC) -MM $(SRC) > $(DEPENDFILE)

-include $(DEPENDFILE)

$(IMAGE): $(OBJ)
	$(LD) $(LDFLAGS) -T$(LSCRIPT) -o $@ $^
	$(OBJCOPY) $@ -Obinary $@.bin

$(BOOTIMAGE): $(IMAGE)
	$(MKIMAGE) $(MKIMAGE_FLAGS) -d $(IMAGE).bin $@

install: $(BOOTIMAGE)
	arm-install-image $(BOOTIMAGE)

curie:
	make && make install && veryminicom
bragg:
	make clean && make && skyeye -d
diels:
	make clean && make && skyeye
debug:
	ddd --debugger arm-elf-gdb --no-exec-window kernel
